package com.example.tool.util.yunda;

import lombok.Data;

import java.math.BigDecimal;

// 订单类
@Data
public  class Order {
    public String orderid;
    public String mailno;
    public Long pay_time;
    public Sender sender;
    public Receiver receiver;
    public String product_name;
    public BigDecimal weight;
    public BigDecimal volume_weight;
    public BigDecimal length;
    public BigDecimal width;
    public BigDecimal height;
    public BigDecimal volume;

    // getters and setters...

    public String toJson() {
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        sb.append("\"orderid\":\"").append(orderid).append("\",");
        sb.append("\"mailno\":\"").append(mailno).append("\"");

        if (sender != null) {
            sb.append(",\"sender\":").append(sender.toJson());
        }

        if (receiver != null) {
            sb.append(",\"receiver\":").append(receiver.toJson());
        }

        // 可以继续添加其他字段...

        sb.append("}");
        return sb.toString();
    }
}

// 发件人类
  @Data
  class Sender {
    public String name;
    public String province;
    public String city;
    public String county;
    public String address;
    public String phone;
    public String mobile;

    // getters and setters...

    public String toJson() {
        return String.format(
                "{\"name\":\"%s\",\"province\":\"%s\",\"city\":\"%s\",\"county\":\"%s\",\"address\":\"%s\",\"phone\":\"%s\",\"mobile\":\"%s\"}",
                name, province, city, county, address, phone, mobile);
    }
}

// 收件人类
 @Data
 class Receiver {
    public String name;
    public String province;
    public String city;
    public String county;
    public String address;
    public String phone;
    public String mobile;

    // getters and setters...

    public String toJson() {
        return String.format(
                "{\"name\":\"%s\",\"province\":\"%s\",\"city\":\"%s\",\"county\":\"%s\",\"address\":\"%s\",\"phone\":\"%s\",\"mobile\":\"%s\"}",
                name, province, city, county, address, phone, mobile);
    }
}
